Hmm, it did work tho...
I tested multiple variations and this should always teleport you back to spawn since the functions of a data pack are always executed at the World Spawn Point.
Note: this is in the section of Data packs and not a command block execution.
since it's executed as @a and not @a
execute as @a[,nbt={Dimension: "minecraft:the_end"}] in overworld run tp @s ~ ~ ~
and it does work for multiple players.
Yours is still better since it requires fewer tests for the execution :)
execute in minecraft:overworld run tp @a[nbt={Dimension:"minecraft:the_nether"}] ~ ~ ~
Thanks for the comment tho!