"I ate when he left."
Translation:Saya makan ketika dia pergi.
Keluar is go outside or exit in a very physical sense. Pergi meaning go or leave is better for the abstract of someone going.
Sudah for already could go at the start but your sentrnce is translated as ' i had already eaten when he had already exited' which is very very clunky and not really the correct transition
sudah at the start only (sudah saya makan ketika dia pergi) would make it 'already i (i already) ate when they left'
Generically though don't put tenses into Indonesian unless they are important and but obvious from connect. Keep it simple.