the reason is the 'w' argumet of fopen()
www.php.net/fopen
there are several options,
i guess you need the a or a+ attribute, which allows for reading/writing the file but opens the file and places the pointer at the end of the file.
the 'w' attribute opens the file for writing, places the pointer at the begining and truncates the file to 0bytes
have a read of the different attributes to get he correct one for you