Success in generating supplier-wise report
I was able to successfully generate a separate file for every vendor.
The mistake I was making is I had kept the stpapi.end.session() inside the loop. I kept the spool.close() inside the loop and moved out stpapi.end.session() and it worked.
I have attached sample script if anybody encounters the similar issue.