The main issue is this but I am not able to solve it yet. On var_dump($array_test[0]) I get the following output:
string '1' (length=4)
This is the reason 'first line' is not echoed as the if condition is not getting true.
Also if you can share your test.txt
file it will be easy to catch the problem.
EDIT : Partial Solution
You can add this line before first if condition to handle this behaviour as described by @Tino Didriksen to get your desired output.
$array_test[0] = substr_replace($array_test[0],'',0,3);