When you compare strings, the comparison works by looking at each character one-by-one until it finds a single character which is not the same in both strings. the entire result of the comparison is then based on the difference between these two characters.
So when you sort strings containing numeric values, the sort order is:
1
10
11
12
13
...
18
19
2
20
21
...
In order to compare numeric values correctly, you would either need to left-pad all the number with zeros so they are the same length when you write the file:
00001
00002
00003
...
00009
00010
00011
...
Or parse the string value to a number and compare those, using int.TryParse on the relevant substring from the file.