When you do a shift on @arraytowrite,
it only gets the first value in the array ($arraytowrite[0])
see the docs on shift.
What you want is:
$writefile = shift;
$text = shift;
@arraytowrite = @_;
You'll have to switch around you params, though.
-- ar0n