Make cmd.script create tempfile in cwd (if passed)

This fixes #3990.