Late, but I thought adding this line before the for loop is helpful.
@echo off
del /S *.m3u
for /R "%~dp0" %%I in (*.cue) do for %%J in ("%%~dpI.") do echo %%~nxI>>"%%~dpI%%~nxJ.m3u"
It deletes any old m3u files beforehand. I found that if you ran it twice, it would just add the same lines again and confuse things.