in reply to calling sub and returning value from the same line

Is error() returning a false value? That would cause the behavior you describe. Remember that <EXPR> and <EXPR> executes the second expression only if the first expression is true. To avoid this dependence on the return value of error() you could try
unless (open FH, ">$_[0]") { error($!, "not able to write to file $_[0]"); return undef; }