Sometime newline ends with ^M .
Its not a matter of "sometimes". It either does, or it doesn't, depending on the operating system.
'\n' translates into whatever the operating system uses as end-of-line. MS-Windows: "\r\n". *nix: "\r". Not sure what MAC uses.