but perhaps its because the Arduino is resetting upon serial 'open' in your script.. and you are sending the data 'too' fast? (before the Arduino is fully booted?)
I have done 'similar' on a PC using PHP (Flash GUI/front end with WAMP server installed locally) to send some serial data to be parsed by the Arduino..
and I either had to pause the script a bit before I sent any serial data.. 'or' manually disable the REST with a resistor on the Aruino board.. so that it doesnt reset upon serial open/close..