Open file in binary mode.

If don't do that, the end of line characters are auto-converted to OS specific ones.
http://stackoverflow.com/questions/9184107/python-file-write-new-line