The cause of this error is that you opened it as O_RDONLY. When you pop() the arrayref, Tie::File tries to remove that line from file too. Do not use pop() to ignore the first line. Iterate starting from the end of your header as my first post or use some regex to ignore unwanted lines
Igor S. Lopes - izut surrender to perl. your code, your rules.