The above code should work perfectly. but, since merlin mentioned a way to avoid freezing of your mIRC, you can use qwerty's perfect solution for that:
Code:
var %a = files $+ $ticks
.comopen %a WScript.Shell
if !$comerr { .comclose %a $com(%a,Run,3,bstr,command /c dir d:\ /a /s /b > d:\found.txt,uint,0,bool,true) }