It wasn’t actually more efficient. Having all of you’re guys in a huge box makes it easier to hit than having you’re infantry spread out. It was mostly a morale thing, having other soldiers within arms range made you reconsider running away. While being engaged with huge volleys by these squares made you very much consider if you should run anyway.
You have to line up musket troops to give them orders too. There’s no radio and you have to shout over the noise and smoke.
Remember, these are black powder guns. They’re loud. If your troops are right next to each other you can more easily direct them to fire, advance, or retreat. Advancing or retreating quickly can take advantage of enemy weaknesses and break up the opposing army. If your guys are spread out, you can’t tell them anything.
I believe the french very much did this. In the Napoleonic wars they mostly used conscripts I believe, so big blocks helped while the British had a more professionally setup army (not that all of its participants were willing either though!) tend to use thinner lines to maximise the shots they could get out.
That’s vulnerable to cavalry charges though, so they had square formations they could get into in order to protect against that.
Both sides then had skirmishers that had more modern tactics to harras and kill officers etc. Some even had rifles. They had to retreat back to the main body if there were cavalry anywhere near though.
One big, deadly game of rock paper scissors