I shouldn't drink wine and code at the same time... Thank you Sir, it works like a charm after the changes, I wanted to make it too complicated!
sub printfToFile {
my $file = shift;
my $format = shift;
my $arrayCount = @_;
my $formatString;
for (my $r = 1;$r <= $arrayCount; $r++) {
$formatString = $formatString."$format ";
}
$formatString = trim( $formatString );
$formatString = $formatString."\n";
open IO, ">>$file" or die "Cannot open $file for output: $!\n+";
printf IO "$formatString", @_;
close IO;
}