Seperate output file according to query string