You can do this with a few lines of code in a luna.lua file put in your episode folder.
--Initialise the death counter to 0 if it hasn't been already
SaveData.deathcounter = SaveData.deathcounter or 0
--Draw the death counter at x = 700, y = 20, and at priority 5
function onDraw()
Text.printWP(SaveData.deathcounter, 700, 20, 5)
end
--When the level ends, check if the player is dying, and if they are, add one to the death counter
function onExitLevel() then
if not isOverworld and player:mem(0x13C, FIELD_BOOL) then
SaveData.deathcounter = SaveData.deathcounter + 1
end
end