 <p><code>ElementAt()</code> has to iterate from the beginning of the collection every time it's called. That's why it's so inefficient.</p> <p>I would suggest another approach - save results generated after last save into a list, and save those results into file from there, not from <code>HastSet</code> itself:</p> <p><em><code>latest</code> list:</em></p> <pre><code>var latest = new List&lt;string&gt;(); </code></pre> <p><em>Adding elements:</em></p> <pre><code>if(storage.Add(newElement)) { latest.Add(newElement); } </code></pre> <p><em>Saving latest to file:</em></p> <pre><code>foreach(var item in latest) { sb.AppendLine(item); } latest.Clear(); </code></pre>