use something like
$fp = fopen($file_name);
$contents = fread($fp, filesize($file_name));
fclose($fp)
(syntax may be complete wrong)
but then you can do whatever you want with contents instead of relying on line by line.
i would also suggest that instead of relying on line by line, you have some sort of 'end of line' signafying character, or you don't allow $stuff($n) to have a new line.
it sounds to me like you really have to learn how to use a database though... you have associations based on unique keys (the line number)... this should really be done is something like mysql.