It's much simpler than you would have thought!
First, let's define what we're talking about - a line = 1 line. Therefore:
This line of code works perfectly.
This line of code doesn't work at all.
This is the only way to use them in a sentence. Combine those sentences, and you get:
This line of code usually doesn't work, but works on this site.
EDIT: Now I looked at the original post and it's a different case than you presented.
In your question here, you wrote, "This line of code does not work ..."
In the original post by Cody Gray, he says, "This line of code did not format correctly."
In case of the past tense exactly as Cody Gray wanted it, the following is correct:
Why did this line of code did not work on Stack Exchange, but worked correctly here on Meta?
BUT, as he started the statement with "did" and then followed with all the cases, he basically wrote it as:
(Why did this line of code)
a) (not work on Stack Exchange), but
b) (work correctly here on Meta?)
I believe what he did there is just plain wrong and should be avoided.
It's important to realize what tense(s) you want/need to use in your sentence(s). What you wanted to ask is this:
Why didn't this line of code format my article correctly on Stack Exchange, but works on meta?
Here you used the past tense in the first sentence and the present tense in the second sentence.
As long as it's currently still a problem you are trying to solve, you should probably use the present tense in both sentences, as the problem is still there:
Why doesn't this line of code format my article correctly on Stack Exchange, but works on meta?
Or, you could say it all in the past tense, for whatever reason:
Why didn't this line of code format my article correctly on Stack Exchange, but worked on meta?
Now that you see how many alternatives there are, it's easy to assume that Cody Gray simply mixed up what you actually wanted to say there and broke your sentence.