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).