Can you give me an example of how you're searching and of what lines you're expecting to see from the search? It's working fine here, though it is definitely fast enough to cause an excess flood if you're getting more than a few results.

Here's the code with /play so that you won't get excess flood with too many results being found. Though, something isn't right if you're getting it stuck on one thing. You do have the $readn line in there, right?

Code:
on 1:text:!search *:#mychannel:{
  var %search = $2
  var %lines = $lines(database.txt)
  var %currentline = 1
  var %total = 0
  while (%currentline <= %lines) {
    var %data = $read(database.txt,w,%search $+ *,%currentline)
    if (%data != $null) {
      write temp.txt %data
      inc %total
    }
    var %currentline = $calc($readn + 1)
  }
  write temp.txt %total found.
  play temp.txt 1500
  .remove temp.txt
}


Also, you can do this just for testing purposes... right after the inc %total line, add:

if (%total >= 10) { halt }

Then, it will stop after 10 rounds. You can then check your out from echo/msg, or you can open temp.txt if you're using /play from this updated script.

Let me know your search command you used, the results you expect to see, and the results you do see after using the halt line above.