Check writing of the sam/bam header and closing of the file for write errors.