The problem is that the script splits a line up into fields using "," as a delimiter and then tries to assign the fields to variables.

One or more lines do not have enough fields but the script doesn't check for this - it just assumes that everything will be OK and then crashes when the data is bad.

GIGO

There is not enough of the original script to safely offer you a full solution, but a simple work-around for the array bounds error is to replace:
 Code:
$array3=split("$x", ",")

With:
 Code:
$array3=split($x+",,,,,,,,,,,,,,,,,,", ",")

This just ensures that there are enough delimiters in the original string to avoid the abend. You will still need to look at the output to determine why the data has gone bad.