Same code working differently on Nano 33 IoT and Mega

It should not make a difference since the both I2C connections (SDA, SCL) both have level shifting which should make them work with both 3.3v and 5v logic.