Replace os.tempnam() with tempfile.mkstemp().