Why batches of same items are not next to each other?

This way of inventory management is due to poor design of inventory stacking [a prominent design flaw]. It would seem these items are added to your inventory based on when you received them, rather than by type or stack amount. There is no way to fix this as it is part of the game code itself, and not a "bug".

As @Crowley Astray had mentioned. If you are still quite upset about this design flaw, you can reach out to CD Projekt Red Support and let them know. There is a chance that they have received complaints on this before, and may patch it in the future.

I hope this helps out!