For some reason I am not getting a new line using document.writeln.
"document.writeln" only creates line breaks in the source code. The browser translates line breaks to spaces if it is not within a <pre> tag. I guess that's the reason why you don't see the line breaks in the browser window. Try to use document.writeln to write contents inside a <pre> tag and you should see line breaks.
You need to add a <br/> tag if you want to see line breaks in the interpreted code.
Also have a look at the answers to these Stackoverflow questions:
Customer support service by UserEcho