Unity does not finish write file (filecontent suddenly ends)

Basically i’ve got this code:

LateUpdate(){
.... some code ....

    using (var stream = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write))
    {
        var writer = new StreamWriter(stream, Encoding.UTF8);
        writer.Write(builder.ToString());
    }
....
}

and the file end suddenly like this:

… 68 148 previous lines …

0.59442 0.10000 0.50537 000

0.59659 0.10000 0.50844 000

0.59875 0.10000 0.51152 000

0.60092 0.10000 0.51459 000

0.6030 <<< — this should look like the previous lines —>>>

The StreamWriter class also does chunked writing. You should either call Flush when you’re done writing to ensure the internal buffers are flushed into the file, ot (which would be the more natural solution) wrap the StreamWriter instance in another using statement:

using (var stream = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write))
using (var writer = new StreamWriter(stream, Encoding.UTF8))
{
    writer.Write(builder.ToString());
}