replaced O_APPEND with O_TRUNC