Trim the output file as opposed to delete to keep same permissions.

Fixes #14979
Add test case for output file permissions

Refs #14979
Merge pull request #15098 from s0undt3ch/issues/14979-output-file-permissions

Trim the output file as opposed to delete to keep same permissions.