i think it is more as question regarding the program flow:
-a- if now new line from arduino is available,
your code try to use the empty / the last vals content
-b- if you save the array ( generated from ONE line ) to the file
( remark: mode overwriting / processing can not append )
the file will contain max only the split-ed last line
writing its array to lines in the file.
-c- also it can work to use the
if (myPort.available()
inside draw, please check on
https://processing.org/reference/libraries/serial/serialEvent_.html
point seems that you try to use data without knowing
- if there are any and
- what is the content
so start again, test line by line, and print the content of the data to console,
use a structure with
boolean diagp = true;
//..
if ( diagp ) println(vals);
so you later can disable that diagnostic printing