in reply to Writing to a different file name

What errors do you get?
Why not check open FILE, "$B_file"; for failure (it can fail just as easy as your attempt to write)?
Why not use File::Copy?