If you can't use a database, then you should first realize that your question has nothing to do with [man]fwrite/man; it's [man]fopen/man that defines which mode PHP opens a file in.
Basically, for this situation, you just need to fopen() the file such that PHP appends to it (rather than truncating to 0 length, a.k.a. deleting the previous contents), and, since PHP automatically advances the internal pointer to the end of the file, [man]fseek/man back to the beginning of the file before writing data.