avoid possible getcwd() errors by switching to another directory before
removing it