Electromagnets not turning off on a Raspberry Grove Base Hat

I’ve just purchased a Raspberry Grove base hat and four Grove electromagnets. I’ve had considerable difficulty setting the magnets up on Legacy Raspbian with Python 3.5 and 2.7, having followed advice I found online that Bullseye using Python 3.9 would not support Grove. First, I followed the instructions on the Wiki Grove Base Hat for Raspberry Pi | Seeed Studio Wiki which completed successfully. I then downloaded the Github repo containing the examples for each sensor. The electromagnet example failed to run since modules di_i2c, periphery and one more di_ module were missing. Running the señor update script and installing python-periphery solved that problem. Looking at the Hat board I noted that the ports were labelled differently from what I had expected esp. D4, which was the port used by the example script, was labelled D5. Running the script unchanged ran with no exceptions being raised, but the magnet would only turn on and not off which renders it useless. I swapped the magnet for another one and the same occurred. I also connected the magnet to the other digital ports and adjusted the script accordingly but none would work with the magnet as labelled. Also when I power off the Pi the magnet does turn off, but a soon as I power the Pi backup it reverts to its previous ON state

Am I doing something wrong or is the hardware faulty? I have run all the update scripts mentioned and i2c and SPI are enabled via raps-config.