The tail suggestion for linux doesn't stop reading and doesn't close the file until you stop it yourself. I program the arduino to send the stuff over and over, and use
cat /dev/ttyUSB0|head -n 5 > fred.txt
It reads 5 lines of output and saves it to a file fred.txt and stops.
You may need to use stty to set the port to the correct baudrate etc beforehand
stty -F /dev/ttyUSB0 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts -clocal
If you're using a new fangled arduino /dev/ttyACM0 is the 'standard' port name rather than /dev/ttyUSB0