Fixed: file descriptor written before file ended.