Any time i play the piano (or any instrument i have some knowledge of) i always end up playing a tune that sounds good to me, but any time i try to find and play a specific melody i always accidentally play some other tune, and get lost in that. Is there any way i can try to play a specific melody in my head?
write it down, and read it. if this seems too hard to do, this might be a cool opportunity to work on reading skills. This is exactly where reading is useful: to play something as planned. which i think is what you are talking about. There's still room for fluctuation within the chart, but the chart will do a wonderful job in keeping you on track, within the song you've meant to be playing