in reply to chdir: failure

Have you checked the value of $CURRDIR to verify that it ends up being what you intend it to be and that the directory exists?