I have the simple code:
f = open('out.txt','w')
You need to open the file in binary mode i.e.
wb instead of
w. If you don't, the end of line characters are auto-converted to OS specific ones.
Here is an excerpt from Python reference about
The default is to use text mode, which may convert '\n' characters to a platform-specific representation on writing and back on reading.