TL;DR
None of the other answers actually addresses your original question of why the command gives a syntax error. This is caused by a missing command between then and else.
A Missing Command
Your original code looks like this:
if lsof "$filename" > /dev/null
then
# file is open
else
echo "deleting $filename"
rm "$filename"
fi
The problem is that you have a comment between then and else, but the comment isn't treated as a command. In short, you could rewrite the problem you have (structurally speaking) as follows:
$ if true; then else echo; fi
bash: syntax error near unexpected token `else'
Fix Your Syntax with a Bourne Builtin
You can fix this problem by placing actual commands before else, but a comment by itself won't do. The if-then section can't be empty; if you want a placeholder, you can use the colon builtin. For example:
$ if true; then :; else echo; fi
Simply placing :
into the section between then and else will fix the syntax error you are experiencing.