Tiny 1-block forks in blk.dat files
This is normal, especially on testnet. What you are seeing are known as stale blocks (or also incorrectly as orphan blocks). These occur when miners complete a block at around the same time so some nodes receive the two blocks in a different order. The conflict resolves when the next block is found.
You will commonly see stale blocks on testnet due to testnet's low difficulty. Furthermore, you see these towards the chain tip because it is only possible to receive these when you are not attempting to do the initial sync. So you won't receive stale blocks during the initial sync, but once you exit that and begin normal operation and your node receives new blocks, you will end up receiving stale blocks (but they aren't necessarily stale yet).
You will need to modify your code to handle stale blocks.