save the current working dir before you change directories, and then change back there?

```python
cwd = os.getcwd()
...
os.chdir(cwd)
```

Also, use `try`-`except` around `os.` stuff (better safe than sorry).