Add to the top of the file:

```
from tempfile import gettempdir
```

and then replace this line with:

```
temp_dir = gettempdir()
```