You should always .Close() the stream to ensure that all the writes are completed. Modify the loop to collect a finite number of samples and then close the stream when the loop is done. Flushing will push the buffer to the stream but not the underlying encoder which may still contain data.
See if that cures the problem.
Also, you should really define the scope for the using statement otherwise there's no point in having it:
using (StreamWriter w = new StreamWriter("abc.txt")) { .... }
With your code structured the way it is, the using statement is redundant anyway, you may as well just declare the StreamWriter without it and let the GC take care of it when it gets disposed at the end of the method.
Hope that helps.
- Adam