Make sure chdir and mkdir pass on their return value

This is needed so errors can be checked.