Use text mode for temporary Python file in tests.

Thanks @myint