You don't define methods inside methods, and you can't open a stream writer on an open file, and you can't overwrite a file that is being read.
As a suggestion, use File.ReadAllText to read your whole file, then add your header text to that, and write it back over the original file:
string path = @"D:\Temp\MyFile.txt";
string data = File.ReadAllText(path);
string withHeader = "The header\n" + data;
File.WriteAllText(withHeader);