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

This fixes #3990.
Merge pull request #4242 from terminalmage/issue3990

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