BAC-891: fclose method moved to write function