When reading/writing files, there is one rule you should follow: Always use rb, wb and ab modes, never r, w and a. r, w and a are Windows specific that change the stream by because of \r. On other platforms r, w and a actually act like rb, wb and ab while when you specify rb, wb or ab, the b will be ignore on non-Windows platforms. This might have to do with your problem.