Refactor copy-to processing

When using a StreamResult(File) in filter processing on Windows, the
output file was left with an open stream. Using a manually closable
output stream fixes this issue.