Earlier quoted context omitted.
No the escort ships do not know exactly where the sub is. On my first submarine duty, we nearly surfaced right in the path of our escort. We had to dive hard to avoid getting run over. “Clearing baffles” is not an exact science.
If the surface escort (whether a fancy warship, or a modest Harbor Patrol boat) was running a cheap commercial sonar set in active mode, and the sub's orders were "stay right under your escort, so long as its course seems reasonable" - with details of 'reasonable' spelled out in written orders - would that be easy to execute without incident?
Longer answer: A cheap commercial sonar isn’t going to find a submarine, even if you know where you’re looking. Submarines are incredible stealthy, and the ocean greatly effects sonar effectiveness, especially from the surface. Due to how it works, surface sonar is nearly useless when trying to locate a submarine.
A popular joke was for us to surface right in the middle of a fleet during war games, or sneak up behind them and take pictures of people smoking and send them to the surface ship’s captain just to mess with them.
With things like towed sonar arrays, and sonar bouys, the playing field can be evened out a bit, but in all the war games I was in, the surface guys could not find us even we told them exactly where we were.
Now imagine that, with an inexperienced submarine crew doing testing, and a surface ship practically incapable of keeping track of us…
“CON, ESM, EMERGENCY DEEP! Hold high signal strength contact bearing 087!”