cmd.script fix: don't try to run script when caching fails

When 'template' resolves to True (the default behavior, since the
default value for this variable is 'jinja') the file is fetched using
cp.get_template. However, no checking was being done to see if the
caching of the script from the salt fileserver was successful, so when
caching fails, an empty tempfile is the result. This empty file is still
run as if it were a script.

This commit inserts a check to see if cp.get_template was successful,
and if not it returns the same error returned in other cache failures.

Additionally, when there was a cache failure, the tempfile allocated
at the start of the function was not being cleaned up, so this would
result in an empty file persisting in /tmp. These have been cleaned up
as well.
Merge pull request #8150 from terminalmage/issue7601

cmd.script fix: don't try to run script when caching fails