fix double cwd when doing --cwd, add test (closes #3300)