What did you try most recently?
Basically, I cant help if I have no idea what you actually did.
Also, be careful:
echo "Success, wrote ($somecontent) to file ($filename)";
will deceive you into thinking that that $somecontent has no new lines, as you are displaying the text in a html page.
As you should know, HTML parses <br> (or <br />) as newlines, not the newline sequence.
You should check the file itself.