Ok. The PATH is getting set, and you are finding /usr/local/bin/exiftool, so life is good. I believe the episode with TextEdit strongly suggests that you need a proper Text editor. You will need to open the code that I posted on Google Drive, and I don't want TextEdit messing that up.
I recommend that you download the free trial of BBEdit. When the trial is over, it will continue to function as a proper text editor. During the trial, there may be updates, and upon trial conclusion, you can simply download yet another trial. This is what I do.
BBEdit will install into your /Applications folder. Once installed, right-click on it and choose Open from the secondary menu. A short verification progress bar will appear, and then hopefully you will get another panel with an Open button on it. Click that too. Now BBEdit can be used normally afterward without repeating this ritual.
Download the code I posted on my Google Drive account. It will go into your Downloads folder as img5.zsh.zip. Just double-click it to reveal img5.zsh. This is what you open with BBEdit, and will copy/paste into Automator as I outlined previously.