Fix Python 3 compatibility

Use only write mode instead of write and binary (the default for
NamedTemporaryFile)