It might be worth putting quotes around those `$filename`s.