Welcome to Joomla Stack Exchange!
It's as simple as \r\n vs \n - text files deal with differently encoded line breaks depending on where you view them. The reverse can happen when you download a file and open it in various programs, and you'll find what was closed up online is double spaced in the editor.
Because each OS have different ASCII chars for ...
Agree with @sharkey send your request via ajax the link above also has a link to a Demo module
You may also want to take a look at the below which shows how to use the JResponseJson which will be useful in returning a response and has some good examples that should help