Move chdir from inside the script block to outside.