You have moved the first row to $header with shift()
In reply to Re: Sorting script deletes first line of data by philiprbrenan in thread Sorting script deletes first line of data by glemley8