I have found slokas in Valmiki Ramayana that convey similar meaning but not exact words, indicating better to perform one’s natural prescribed duty, though tinged with faults, than to perform another’s prescribed duty, as told by Sri Krishna in BG.
In Yuddha Kanda, Vibhishana takes Lakshmana to the place where indrajit is performing the sacrificial rite. He advises Lakshmana to destroy Indrajit even before he finishes the sacrificial rite at a banyan tree. Indrajit sees Vibhishana there and starts talking harsh words to him, saying that he has ditched him by bringing Lakshmana to that place.
शोच्यस्त्वमसि दुर्बुद्धे निन्दनीयश्च साधुभिः | यस्त्वं स्वजनमुत्सृज्य
परभृत्यत्वमागतः || ८७-६-१३
"O evil-minded one! You are pitiable and deserve to be reproached by
the virtuous, in that having abandoned your own kind, you have entered
into the service of our enemy."
नैतच्छिथिलया बुद्ध्या त्वं वेत्सि महदन्तरम् | क्व च स्वजनसंवासः क्व च
नीचपराश्रयः || ८७-६-१४
"You are not recognizing the great difference because of your feeble
mind. Where is living together with one's own kindred and where is
taking refuge with low kind of enemies?
यः स्वपक्षं परित्यज्य परपक्षं निषेवते | स स्वपक्षे क्षयं प्राप्ते
पश्चात्तैरेव हन्यते || ८७-६-१६
"He who, abandoning his own side, takes sides with adversary, is
killed, after his own knsmen are destroyed just by those people of the