The “characters of…” command actually returns a list of the characters, not a string… so you have to manually coerce it into a string. Try changing…
return theFileCode
… to …
return (theFileCode as string)
The fact that it’s returning the characters on a new line and not logging them as a list or string might indicate that you’re setting your text item delimiters to “return” somewhere in your script and not ever setting them back to the default. If so, make sure to set your delims back to {“”} when you’re done, or it can screw up a lot of other commands that you may not expect.