in reply to Replace a line with a new one

$array[3] = "The new text\n";

Why does your code loop through the whole array when the index is known?

After Compline,
Zaxo