Wow
Sonar can detect you under the ship but cant detect things at the surface.
Also I would think that the merchants motor noise would have drowned out your electric motor.
Here is an escape technique I use and is effective. Sonar works terrible near the surface and the worse the weather the worse sonar works. So in bad weather I just go silent and stay at periscope depth and never get detected even if they are a stones throw away. It takes Balls but it works in. I use GWX3.