Trotting can be hard to get the hang of! Like skiing, it sometimes clicks, but usually it just takes a lot of practice and time.
I'd suggest focusing on your heels. Sinking into them is what will really help you stay in your seat, even when you're posting--focus on keeping your heels and legs in the same position, as a lot of beginners tend to move them up and down as they post and that's what can be really unbalancing. Focus on sinking into your heels and gripping with your calves will help. Also, take deep breaths and make sure you're sitting upright rather than leaning too far forward--a natural response to trotting is leaning forward, but it'll really get you off balance so try and focus on sitting upright or leaning a teeny bit further back (like a dressage rider) to keep your balance.
And yes, trying it on the lunge line is good--that way you won't have to worry about your hands and steering and such, but can focus on keeping your seat. It's a lot of things to do at once, so it helps if you can be on the lunge! Good luck :)