Correct write() calls to set lastwrite correctly