read received data from xbee to file

I have arduino with xbee sending sensor data to xbee(explorer)

How can i write new values to a file? I can do cat /dev/ttyUSB0 > file.txt. Problem is that it will be a continous stream and i dont know how to separate new values from existing.

I could do head -n4 /dev/ttyUSB0 but it reads from wrong state of stream. It wont read the first sensor an so on.

Sould i add that it prints X at the first line and Y to last line and somehow save everything between them? How to do that?