Add 'b' to open the tmp-file in binary-write mode