Replace pushd/popd with Dir.chdir.