The problem could be that, depending on your text (and OS?), line breaks can either be "\n", "\r", "\r\n", or "\n\r". Your code only looks for "\n", so if your text also has "/r" as part of the line break, then you code leaves these in, and your output text can still appear to have line breaks.
Try this code instead:
This page might help you out :
http://dotnetperls.com/string-split
I have a macro that I have been using that does something similar, but uses Regular Expressions:
Using RegEx, it looks for one or both "\r" and "\n" and removes them.
If you just want to clear the empty lines (and not worry about the whitespace), you can just use the last RegEx in the code above.
I haven't fully tested this, but it seems to work well for me. Let me know if you have any trouble.