The problem is you're reading the file one line at a time. If you find a blank line, you're essentially replacing it with another blank line, so there's no net change.
If you process it one line at a time, you need to write nonblank lines out to a separate file as you go, so it will have the nonblanks when you're done.
If you know the file won't be too big, I think you could also use this regex: