Use safer chdir method (File::chdir)

Resets directory after scope has ended.