have a look at http://docs.python.org/2/library/tempfile.html for this. can be used as a context manager

```
with tempfile(...) as ud_file:
   ...

```

that way you get cleanup even if the test fails before it gets to the end