It might be that "exiftool" already has the functionality needed - quote from the man page:
exiftool '-FileModifyDate<DateTimeOriginal' dir
Use the original date from the meta information to set the same file's filesystem modification
date for all images in a directory.