Well.. your main problem may be that part:
sockread %chan.data
while ($sockbr) {
sockread %chan.data
}
That means that you execute /sockread until there's nothing left in your in-buffer...
/sockread reads only 1 line out of the buffer, and it can also hold only 1 line in your variable.
That means that %chan.data will only hold the last line of the buffer after that code.
All your code that works with the page-source must be inside this while-block.
You could also use the goto-method as shown in the example in the mirc help - /help /sockread
Additionally, after this problem is fixed, your script will try to use bwrite with %chan.data - which is not a binary variable!
I'm not sure if it's really necessary - but I recommend to use binvars to download files...
And also.. you will have the http-header inside the file-data, which breaks the file.