As previously said, in the text file the lines are formatted like so:

Name1 - IP1
Name1 - IP2
Name1 - IP3
Name2 - IP1
Name2 - IP2

I used a temp file which only has these 5 lines.

In the channel I do the trigger '!search Name1' (I expect it to return any lines which contain 'Name1' in the first field) and it returns the first result 'Name1 - IP1' from the text file and then immediately afterwards is flooded off the server.

From your code, I made only the obvious change (the channel name). I replaced all 3 instances of 'mychannel' with the actual channel.