Grepping and sorting should do it for your script.
It looks like the file you have a blank space in is already assumed to exist in this script (doesn't get created in it).
Do you know what other script (or program) creates the file? That might be the easiest way to prevent the blank line from appearing at the top if you don't want it there.
It's probably a good idea, if that happens enough, to include some functionality in your code to strip blank lines before you parse the file.
Otherwise, the above posted answers are both good ways to deal with your issue.
, Mike