StreamWriter has some options of usage. You can as add new text to an existing text in file, so and to clean existing text and add a new one.

The 6th option of usage StreamWriter is (string path, bool append, Encoding encoding)

To truncate data in a file, you should use something like this:

using (StreamWriter sw = new StreamWriter(cmdFilePath, false, Encoding.Default))
{
   String presentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
   sw.WriteLine(text);
   sw.Close();
}

 

If you want to add new text to a file, use true instead of false:

using (StreamWriter sw = new StreamWriter(cmdFilePath, true, Encoding.Default))
{
   String presentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
   sw.WriteLine(resultCommands);
   sw.Close();
}