Slow algorithm to insert strings into indexed file in alphabetical order