When sending the html directly to the browser (not writing to file and using the above declaration), the browser (chrome) appeared to be ok, and displayed the full html.
Processing the text through normalize-unicode() didn't help. The error persisted. Is there a way to fix the text before submitting it to file:write()?