Use NamedTemporaryFile instead of mkstemp