Sounds you have to enhance your code by the following logic
- in your loop, split your $data[$i] into an array containing words
- write the line to a new array if not all of the columns 2, 3 and 4 are zero
- after your for-loop, delete the file
- if the new array contains entries, write them to the file (you actually recreate the file that way)
HTH, Rata