Usando C++ puoi fare: (ho scritto il carattere spazio come esadecimale perché non era molto visibile).
codice:
#include <fstream>
#include <iomanip>
using namespace std;
int main() {

	ofstream of("d:/zxc.txt");
	
	of << setw(5) << setfill(0x20) << 1 << endl;
	of << setw(5) << setfill(0x20) << 12 << endl;
	of << setw(5) << setfill(0x20) << 123 << endl;
	of << setw(5) << setfill(0x20) << 1234 << endl;
	of << setw(5) << setfill(0x20) << 12345 << endl;

	of.close();

	return 0;
}