in reply to printing text to a file in binary
The text from the textarea probably does its line breaks with just \n, while your text editor (Notepad?) requires both \r\n. You should try removing all instances of \r and then replacing \n with \r\n. This will hopefully fix your problem.