I've found an issue with Gen 4 save files. If I edit or delete a Pokemon that's saved in a PC box slot, the save file corrupts. The same thing happens if I drop a Pokemon to a new slot. I'm able to load the edited save without any problems, but if I then save in-game and reload, the save file is then corrupted and is reverted back to my original save, before any edits were made in PKHex.
I've tried this in Heart Gold and Soul Silver using real cartridges with a New 3DS with the latest CFW. I'm using the latest version of PKHex and TWLSaveTool.
I believe the bug lies within PKHex as, if I make the same edit to a party Pokemon, the save is fine - this indicates that TWLSaveTool is restoring the save file correctly.
I've tested this in Platinum and both editing party and PC Pokemon are fine there. It only seems to be a problem in Heart Gold and Soul Silver. I don't own Diamond and Pearl so can't test those.
UPDATE - I've attached some save files:
POKEMON SS.0.sav is completed unedited by PKHex. I'm able to restore it and save over it without any problems.
POKEMON SS.1.sav is edited - I've added the move Fly to the Pidgey in Box 1. I'm able to restore it and save over it too.
POKEMON SS.2.sav is also edited - I've deleted the Pidgey from the box using PKHex. I'm able to restore it to the cartridge but, if I save over it, the data is corrupt when I reload.
UPDATE - 13/12/2018
I feel stupid for not having tried this before but... if you save over an edited save in-game and reload, you get the data corrputed message and it reloads your save previous save. If you then load that save, and overwrite it again in-game, it'll save properly and retain your changes. You get the "saving a lot of data" message, indicating that it's save both the main save and the backup.