You can do it like this:
PROMPT_COMMAND='[[ $? == 0 ]] && history 1 | sed -r "s/\ +[0-9]+\ +//" >> successful'
$PROMPT_COMMAND holds a command which bash executes before issuing a prompt. So what this does is evaluate the exit status of your previous command (after you press enter to execute your current command, but before bash evaluates it), and if it was successful, pull it from your bash history, strip the command number, and put add it to a separate file.
Now you don't have to tack on anything to your commands:
echo "exits successfully and will be appended"
ehco "only ends up in bash history"
Note that the readline history commands, !! and the rest of its family, only works in interactive shells, you cannot use those in scripts.
Also note that the -r option is gnu sed, bsd sed does not have it.