Yes, because that is what you are telling it to do!
You create your headers at the top of the method, and append the whole data to the file at the end.
If you look at the documentation (
StreamWriter Constructor (System.IO) | Microsoft Docs[
^]) then you will see that this code:
Dim tw As System.IO.TextWriter = New System.IO.StreamWriter("E:\SAT\Work.io\Work.io\bin\Debug\Session.csv", True)
Specifically opens the file stream to append data, so the original data isn't overwritten.
If that isn't what you want to do, then change the
True
to a
False
to throw away the existing file content first, or change your code at the start of the method to detect if you need to add headers. That may be as simple as "does the file exist?" or you may have to be cleverer than that and check the file content to see if there is a header line (or indeed any data at all).
How many times do I have to tell you to stop guessing and start thinking? :laugh: