We get a file descriptor as returned by os.open() when calling tempfile.mkstemp(), so we need to pass that value to os.fdopen() before we can write text to it (easily, anyway).
Init named parameters to None rather than other variables (copy and paste gets me again).