Well you could use KiX to write the entry, but that aside.

I would recommend placing your data into a variable and then doing a single write.

$objfile.writeline

one time instead of over and over. That would speed up the script quite a bit.