I have a program which writes websites to the hosts file from a .txt file which has a list of websites, so that next time a website is searched, the connection is closed.

It works great! However, because the program is told to keep writing websites to the hosts file, the file size is starting to grow. Since I have a large list of websites, if I keep writing those websites every time the application is ran, too much storage will be used up.

So, I thought that by removing the lines of text added until there a no more clones would be a good idea, so I tried using this code:

Code:
Dim text As String = File.ReadAllText("C:\Windows\System32\drivers\etc\hosts")
        Dim index As Integer = text.IndexOf(line)
        If index >= 2 Then
            Dim delLine As Integer = 10
            Dim lines As List(Of String) = System.IO.File.ReadAllLines("C:\Windows\System32\drivers\etc\hosts").ToList
            lines.RemoveAt(delLine - 1) ' index starts at 0 
            MessageBox.Show("Clone Removed.")
        End If

However, it doesn't work. The MessageBox shows up when the file has over 2 copies of the black-listed website, but it doesn't remove those new entries.

How can I remove text clones from the hosts file (or a .txt file) so that only one copy of the original text is stored, and not just text being written all the time?