in reply to subroutine not working

This does not look right. You are not checking the status of open:
open (DATABASE, "$filename" || &ErrorMessage); # Did you mean this? You should also probably pass '$!' to # and include '$!' in ErrorMessage open (DATABASE, $filename) || &ErrorMessage;
But if you're just checking for any content, why not just use -s $filename??