I don’t know how other states do it, but I’m assuming you’re given a “ballot ID” that your vote is associated with (instead of your name). So if someone opened your vote-by-mail ballot, all they’d have is your ballot ID, so they wouldn’t know who voted for who.
Also, what stops someone from doing that with the current voting system? We have computers do the counting with little to no oversight; They could easily be programmed to report people who “voted the wrong way.”
With regards to your variation, that’s an inherent weakness of vote-by-mail, yes. There’s not much that can be done about that other than outlawing vote-by-mail.[^a]
[^a]: Due to the way the Constitution is written, the power to decide the method of voting is not with the federal government. As such, the Tenth Amendment delegates that power to the states. Meaning, the power to require “secret ballots” rests with the states, and many do not have such requirements in their Constitutions. It also means that the federal government can’t outlaw vote-by-mail without a Constitutional amendment.