Catch system errors when writing a file - Fixes [#46398849] and [#45964327]

When there's an error writing a file (i.e. no space left on device, ...), director will pass the error message to CLI.