generate.py specifies encoding for test files

On many Windows systems, the default encoding is not utf-8. If there are
test files containing non-ASCII characters that do not map properly to
the default encoding, generate.py crashes.