Add missing error check when calling chdir()