unfortunately it's been way too many years since I've bothered recording via midi.
It sounds like you've got some sort of a midi loop happening.
I don't have cakewalk so I really can't be of much help.
Normally you have the midi OUT on p.c going to midi IN on keyboard and midi IN on p.c. to midi out on keyboard.
When recording from keyboard to computer you have to set the sync ( midi clock) in cakewalk to external.( ie it's waiting for you to press start & start playing) When playing back your song you set the sync in cakewalk to internal so that it will playback.
Unfortunately I'm not quite sure which settings to use in the kn itself, but when cakewalk sync is set to external, your keyboard sync would be set to internal and Vice Versa.
What exactly are you trying to do?
Normally on my kn7 I would record the song using the internal sequencer. Use the apc to midifile function and turn the song into a midifile. Then load it into one of my p.c sequencers for further editing ( or whatever)
Then I could resave the midifile ( with edits etc) and load it back into my kn7.
Saves having all the hassles of recording via midi cable.
If this method would work with what you're trying to achieve, let me know and I can give you more detailed intructions( your keyboard has to have apc to smf capabilities)
Korg PA4x, Korg PA3X, PSR S950, Band in a Box 2018
V Arranger/Ketron SD2