Printf will perform decimal to binary conversions without any extra code:
#!/usr/local/bin/perl
##open(DAT, "<", "datafile.txt") || die("Could not open file!\n$!\n"); # uncomment when ready
open(FILE, ">", "output.txt") || die("Could not open file!\n$!\n");
while (<DATA>) # change to 'DAT'...