Everything needs to be even to have the best chance of cutting straight. Depth gauges need to be all the same shape, and same height relative to each tooth. I like to at least have each pair of right and left teeth equal in length, but prefer all teeth are equal length. All teeth need to be sharp on the top and the outer side, all sharpened at the same angles, all sharpened with the file at the same height which affects the sharpness and feed rate the teeth try to dig into the wood. The bar rails must be an even height, the groove not too wide, the bar not warped. It may be possible for a worn bar with closed rails to end up with an out of square groove.
When I was less experienced with sharpening, I would get a new chain once they started cutting crooked beyond my efforts to correct, and sometimes a new bar was needed too. It can be easy to miss dull side plates on the cutters since we normally look at the top edge and corner for sharpness, but a dulled side edge will make it cut crooked. A rock or something could have dulled the side edges on one side of the chain.