Fix encoding when the text is written directly in the file