Replace chdir to /var/empty with secure creation of tempdir and later removal

Replace chdir("/var/empty") with chdir(emptydir) where emptydir is securely created by tempfile module. After actions complete the dis is removed with shutil.rmtree.

This way the code becomes a bit more portable and not so dependant on specific dir existence (LXC being one of the cases, ubuntu the other, and my specific case the third)

PS: The diff is a bit confusing but in reality the chdir call (and some code after it which i believe is protected by it) is wrapped in
```
  try:
    ....
  finally:
    try:
    ....
    except:
```