SMBX is finicky with overlapping tiles, and draws each tile randomly whenever the level is loaded. (as far as I know). The best way to avoid this is to make the SMW dirt a background object and place it where the cave tiles are supposed to overlap.
You can also use sizables because they are a bit more into the background and/or others you can use background objects and the regular tiles invisible... but that is more time consuming.