If the result of what you thought was a perfect ball strike, is a ball flight that’s off track, then don’t get angry or frustrated. Get back to basics.
If you want a straight ball flight after impact, the spin axis needs to stay horizontal.
If the club face is not square to the path of the club through impact, then the spin axis of the ball will be titled. In this case (as shown below), the ball is going to move left to right.
Are you playing with a golf ball that assists with reduced spin? Is your lie angle fitted to your swing so that you’re more easily able to square the face at impact? If you want straighter ball flight, your answer to both those questions should be “yes”.