Whitespace is ignored in HTML (as well as PHP, although a linefeed in a string is a char, so it will retain those).
Wrap the content into nl2br() function prior to outputting (don't do it before inserting).
That will insert a <br/> before the \n, so the HTML is given a breaking space to force the newlines.
print nl2br("Text with \nLinefeed in it.");
Will result in
Text with <br />
Linefeed in it.