This works but I don't know what the last section does. If I remove it the code segfaults, so I'm assuming it is somehow related to closing the file or handling memory allocation but as far as I am aware that what the 6 instruction is for.
section .data
msg db 'Hello, world!', 0xa
len equ $ - msg
outfile db 'test_file.txt', 0
section .text
global _start
_start:
; creating and opening
mov eax, 8 ; set instruction
mov ebx, outfile ; set file name
mov ecx, 544o ; set file permissions
int 0x80 ; make system call
; writing to file
mov ebx, eax ; move file descriptor from previous call
mov eax, 4 ; set instruction
mov ecx, msg ; set text
mov edx, len ; set number of bytes to read
int 0x80 ; make system call
; closing file
mov eax, 6 ; set instruction
int 0x80 ; make system call
; closing program?
mov eax,1
mov ebx,0
int 0x80