i thought assignfile is part of rtl , so is not necessary to include its unit !
note i have a fresh installation of fpc 3.0.4 win 32bits
AssignFile is included only if you set one of the modes that use objpas by default (DELPHI or OBJFPC) so you can either add {$MODE OBJFPC} or {$MODE DELPHI} (or use the equivalent compiler parameters):
{$mode objfpc}
program test;
var
f: textfile;
begin
AssignFile(f, 'ATestFile.txt');
{... etc ...}
end;
or use the good old
Assign(file, filename)program test;
var
f: textfile;
begin
Assign(f, 'ATestFile.txt');
{... etc ...}
end;
Lazarus, by default, uses ObjFPC mode but the console IDE (and the command-line compiler) use FPC, the "Free Pascal dialect" mode. Thence the different result with each.
ETA: Note that you can also change mode in the options of the text-mode IDE: see attached image. Although my recomendation s to add it the "mode" switch in the source so that it applies always.