Temp file should be open in binary mode