Tmpdir cleanup errors

Windows tests on Python 3 are failing in these places because the `TemporaryDirectory` context manager attempts to clean up files or folders that are still in use. On Python 2 the code was just ignoring the errors.

I think these changes should resolve it. In two cases, we can use the new `TemporaryWorkingDirectory` context manager, which actually makes the code simpler.