That's known bug: non-100%-correct prediction of next file location, because different cameras have different settings of switching of current folder.
A long time the CHDK saved all RAW files only in a single directory with its own file numbers. The discovering of file counter (to be in sync with JPEG files) was so long process, so when it was implemented it was a huge success as such.