I had this many years ago. As you say, you can copy it to an older project and it mysteriously starts working again.
I found it was down to an erroneous character in the source code, the exact character I don't recall, but it was something like a tab between the actual code (rather than at the beginning of the line.
Step 1 is to cut the code, paste it into Notepad, then cut and paste it back. If it's a character out of range of the displayable characters this will eliminate it.
Then you need to work out how it's getting in there, so you can stop it altogether. Is it in the template code for a new project?