Some things cannot be helped, like getting sucked out to trips by a guy with only one pair. Or a guy with an ace and getting board screwed like you did.
However, I always use the most caution with two pairs when there is a single overcard. While trips are always possible, I'm more leery of the overs. If they flop a set you will know because they will most likely wait for you to bet so they can raise. With an overcard giving someone top pair, they will often call even if given bad pot
odds, unless it's a scary board. Problem with that is, it will be scary for you as well! With top pair, now they have a good chance to outdraw you if the board pairs runner runner or they hit their kicker, which very well could be higher or lower than either of your pairs - it doesn't matter, they have that top pair already.
When I get nasty with my two pair is when I also have a backdoor straight (not to the dumb end) or a flush to go with it. Then if I get called, I still have more outs than with "just" two pair, which is only 4. Then, If I think the guy might be drawing to a better 2 pair, I'll know I'm going to make some chips if he hits his second card. Hopefully, his second card also completes my st8. That's just a pure joy-gasim right there buddy.
Just last night I watched a guy flop top two (Q-10) on a K-10-Q board. After a substantial Cbet failed to make one opponent fold, he bet big again on the turn, which was a Ace. After getting re-raised, I knew what happened; the guy had to have a J. What else could he re-raise with? And most likely he wouldn't
bluff at that board...so, the guy with Q-10 then shoved, and sure enough, they guy called and showed a J (J rag, to make matters worse) for a straight. The other guy probably knew he was beat, but was hoping to hit his 4 outer, which is never good, frankly.
All told, you did learn a very good lesson. Your 2 pair can get counterfeited by overcards, either on the board or in the guys hand. Even a turn/river runner runner pair like 9-9 or just another K would have killed you (You, 8-8-9-9-K vs Him 8-8-9-9-A OR You, 8-8-K-K-6 vs Him 8-8-K-K-A) This also happens when someone with a pocket pair and a board pair gets stubborn, when the board pairs again and counterfeits the 2 pair they have!