F# Writing to file changes behavior on return type
<p>I have the following function that convert csv files to a specific txt schema (expected by CNTKTextFormat Reader):</p>

<pre><code>open System.IO
open FSharp.Data;
open Deedle;

let convert (inFileName : string) = 
    let data = Frame.ReadCsv(inFileName)
    let outFileName = inFileName.Substring(0, (inFileName.Length - 4)) + ".txt"
    use outFile = new StreamWriter(outFileName, false)
    data.Rows.Observations
    |&gt; Seq.map(fun kvp -&gt;
        let row = kvp.Value |&gt; Series.observations |&gt; Seq.map(fun (k,v) -&gt; v) |&gt; Seq.toList
        match row with
        | label::data -&gt;
            let body = data |&gt; List.map string |&gt; String.concat " "
            outFile.WriteLine(sprintf "|labels %A |features %s" label body)
            printf "%A" label
        | _ -&gt;
            failwith "Bad data."
    )
    |&gt; ignore
</code></pre>

<p>Strangely, the output file is empty after running in the F# interactive panel and that <code>printf</code> yields no printing at all.</p>

<p>If I remove the <code>ignore</code> to make sure that there are actual rows being processed (evidenced by returning a seq of nulls), instead of an empty file I get:</p>

<p><code>val it : seq&lt;unit&gt; = Error: Cannot write to a closed TextWriter.</code></p>

<p>Before, I was declaring the <code>StreamWriter</code> using <code>let</code> and disposing it manually, but I also generated empty files or just a few lines (say 5 out of thousands).</p>

<p>What is happening here? Also, how to fix the file writing?</p>