[clang] Report errors from writing the PCM instead of crashing (#243333)
The `writeImpl()` function never checks the `raw_fd_ostream` for errors.
If writing the PCM fails (e.g. because the disk is full), the stream's
destructor reports a fatal error instead of `writeImpl()` returning the
error code to the caller. This PR checks the stream for errors, closing
it explicitly to also catch errors reported on close, and returns them.