Read 1st col values of a *.ref file and create *.brt files for each diff val

I couldn't write what I had sone further, to my previous thread, as it was closed, as such had to create a new thread. Apologies for the same.

I had modified my program with the following code to read each value of column 1 of my input file (*.ref) and create multiple Output files (*.brt) with name as the value at the column 1 of the input file. For each change in the value at column 1 of input file, a new output file (*.brt) should be created. But it doesn't seem to do what is required and when I run the application it gets hung. Could you please help me with the changes to the following code so that it works :-