Fix dirhistory when the directory contains spaces

pwd output is not escaped, so when changing to a directory like "space dir", only "space" gets saved in the history. This fix wraps `pwd` in double quotes to mitigate that.