Fixed problem of writing empty file