use getcwd() instead of cwd()

getcwd() does a C library call to getcwd and avoid making a new process
for `/bin/pwd` (that probably does the same thing).