Fix dummy file encoding bug

When testing to see if a file is a raw dummy file, we used to open the
file in text mode with default utf-8 encoding. Binary files could cause
encoding errors.

Dummy files are now read in binary mode and their headers are also
written in binary mode.