You can sometimes innocently include some text into your script that when presented with adocument.write() gets completely misunderstood by the HTML parser. This will almost certainly be due to the presence of "<" and ">" characters in the output. It is likely that the browser will see what it thinks is a tag, but then ignore it according to the "I don't know what it is - so I won't display it" rule, as it won't be a recognized tag.
Use HTML escapes to output the character as intended.
This is important for the following characters if not for others:
< becomes <
> becomes >
& becomes &