How save the predicted images with the name of the image in test file?

I am new to fastai, I will be thankful if you could help me to find a solution for this problem. I am trying to use segmentation for a data collection with 987 images, and I want to export my predicted images with the name of their real image(used as input in test file)?

This is the code that I used for predicting:
dl = learn.dls.test_dl(fnames[:])
preds = learn.get_preds(dl=dl,reorder=False)
for i, pred in enumerate(preds[0]):
pred_arg = pred.argmax(dim=0).numpy()
rescaled = pred_arg.astype(np.uint8)
im = Image.fromarray(rescaled)’/content/drive/MyDrive/classification/CNN_segmentation/big_Image/pred_all_tiff’)
Also, the order of predicted images does not match the order of images in the test file.