From 2008, but still applicable:
https://nealabq.com/blog/2008/09/15/bugs-returned-mem-refs/
This is the first line of the file
then during execution of ++$#$_
the result is the same as if you had written ++$#{This is the first line of the file}
So the variable @{This is the first line of the file} goes from undefined to an array of length 1, turning $#{This is the first line of the file} to 0.