Thank you. I was able to achieve what I wanted by saving all filenames in the directory into a list.
filelist=Files In Directory( path1, recursive);
Then I created another list of the unique IDs.
unitIDlist = {"AA", "AB","AC"};
Finally I used Nested For loop to find the files that contains unique IDs in the filename and open and concatenate them to the first file.