Likely, much of the advice and suggestions you have already received will lead you to the problem and the cure. However, I simply wish to point out that real locomotives quite often are seen to "wander" side to side between the rails, especially ones with shorter wheel-bases on older, less well maintained track that has sags and humps on one rail or the other, or both.